import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:lzj_demo/pages/index/index.dart';
import 'package:lzj_demo/pages/video/video.dart';
import 'package:lzj_demo/pages/my/my.dart';
import 'dart:convert';

//* important infomation
//? should this method to be exposed in public
//todo implement createState
//! Alert

void main() {
  //todo  设置状态栏颜色和字体颜色
  SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
    statusBarColor: Colors.transparent, // 设置状态栏透明
    statusBarBrightness: Brightness.light, // 设置状态栏字体颜色为dark白色,light为黑色
  ));

  runApp(const MyApp());
  test();
}

void test() {
  String encodedTokenChallenge =
      'AAMAFWh0dHA6Ly8xMjcuMC4wLjE6NDU2NyAlIZ9LyABISQ5IXh-kL5g280wmK8JPrRoa14LLTdGrGgAwMTI3LjAuMC4xLDEyNy4wLjAuMSwxOTIuMTY4LjAuMTc4LDE5Mi4xNjguMTkuMTMw'; // Base64编码的字符串

  // List<int> decodedBytes = base64.decode(encodedString);
  // String decodedString = utf8.decode(decodedBytes);

  // 将Base64URL编码的字符串转换为Base64编码的字符串
  String base64EncodedString = base64Url.normalize(encodedTokenChallenge);

  // 替换URL安全字符
  base64EncodedString =
      base64EncodedString.replaceAll('-', '+').replaceAll('_', '/');

  List<int> decodedBytes = base64.decode(base64EncodedString);
  String decodedString = utf8.decode(decodedBytes);

  print("decodedString==>  " + decodedString); // 输出: "Hello World!"
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      //todo 隐藏右上角的debug
      debugShowCheckedModeBanner: false,
      //todo 在localizationsDelegates中指定哪些Widget需要进行国际化用于生产本地化值集合的工厂我们这里指定了Material、Widgets、Cupertino都使用国际化
      //todo 需要在yaml先指定 flutter_localizations:sdk: flutter
      localizationsDelegates: const [
        //* 本地化的代理类
        GlobalMaterialLocalizations.delegate, //* 指定本地化的字符串和一些其他的值
        GlobalCupertinoLocalizations.delegate, //* 对应的Cupertino风格
        GlobalWidgetsLocalizations.delegate //* 指定默认的文本排列方向, 由左到右或由右到左
      ],
      //todo supportedLocales指定要支持哪些国际化我们这里指定中文和英文（也可以指定国家编码）
      supportedLocales: const [
        Locale("en", "US"), //* 美国英语
        Locale("zh", "CN") //* 中国简体
      ],
      locale: const Locale('zh'),

      title: 'Flutter Demo',
      theme: ThemeData(
        //todo colorScheme：设置主题色
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.purple),
        useMaterial3: true,
      ),
      home: const MainPage(title: '法律服务'),
    );
  }
}

class MainPage extends StatefulWidget {
  const MainPage({super.key, required this.title});
  final String title;
  @override
  State<MainPage> createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  final List pages = [const IndexPage(), const VideoPage(), const MyPage()];

  int _selectIndex = 0;

  void onTap(int index) {
    setState(() {
      _selectIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    //* 一个完整的路由页可能会包含导航栏、抽屉菜单(Drawer)以及底部 Tab 导航菜单等。
    //* 如果每个路由页面都需要开发者自己手动去实现这些，这会是一件非常麻烦且无聊的事。幸运的是，Flutter Material 组件库提供了一些现成的组件来减少我们的开发任务。
    //* Scaffold 是一个路由页的骨架，我们使用它可以很容易地拼装出一个完整的页面。
    return Scaffold(
      // appBar: AppBar(
      //   backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      //   title: Text(widget.title),
      //   centerTitle: true
      // ),
      body: pages[_selectIndex],
      //todo
      bottomNavigationBar: BottomNavigationBar(
        items: const [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
          BottomNavigationBarItem(icon: Icon(Icons.video_call), label: '视频'),
          BottomNavigationBarItem(icon: Icon(Icons.my_location), label: '我的')
        ],
        currentIndex: _selectIndex,
        selectedItemColor: Colors.purple,
        unselectedItemColor: Colors.grey.withOpacity(0.5),
        showSelectedLabels: true,
        showUnselectedLabels: true,
        elevation: 0,
        onTap: onTap,
      ),
    );
  }
}
